home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / ViewerGWorldTest ƒ / ViewerGWorldTest.c next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  2.3 KB  |  121 lines  |  [TEXT/CWIE]

  1. /*
  2.  * Hack to show how to use the viewer to make pictures.  Click to quit.
  3.  * nickt@apple.com
  4.  */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <time.h>
  8.  
  9. #include <StandardFile.h>
  10. #include <QuickDraw.h>
  11. #include <QDOffscreen.h>
  12. #include <Windows.h>
  13.  
  14.  
  15. #include "QD3DViewer.h"
  16.  
  17.  
  18. Boolean            gQuitFlag = false;
  19. WindowPtr        gMainWindow        = nil ;
  20.  
  21. void InitToolbox()
  22. {
  23.     Handle        menuBar = nil;
  24.  
  25.     MaxApplZone() ;
  26.     MoreMasters() ; MoreMasters() ; MoreMasters() ; 
  27.     
  28.     InitGraf( &qd.thePort );
  29.     InitFonts();
  30.     InitWindows();
  31.     InitMenus();
  32.     TEInit() ;
  33.     InitDialogs(0L) ;
  34.     InitCursor();
  35.     
  36.     FlushEvents( everyEvent, 0 ) ;
  37.     // initialize application globals
  38.     
  39.     gQuitFlag = false;
  40.     
  41. }
  42.  
  43. Boolean MetafileFileSpecify( FSSpec *theFile )
  44. {
  45.     StandardFileReply    theSFReply ;
  46.     SFTypeList            myTypes = { '3DMF' } ;
  47.     const short            numTypes = 1 ;
  48.     OSErr                 myErr ;
  49.     
  50.         
  51.     StandardGetFile( nil, numTypes, myTypes, &theSFReply ) ;
  52.     
  53.     if( theSFReply.sfGood )
  54.         *theFile = theSFReply.sfFile ;
  55.     
  56.     return theSFReply.sfGood ;
  57.     
  58. }
  59.  
  60. void main(void)
  61. {
  62.     TQ3Status    myStatus;
  63.     Rect        rBounds = { 50, 50, 350, 350 } ;
  64.     Str255        title = "\pSpinning Box" ;
  65.     FSSpec        theFileSpec ;
  66.     OSErr        myErr ;
  67.     GWorldPtr    myGWorld ;
  68.     
  69.     InitToolbox() ;
  70.  
  71.     if(MetafileFileSpecify( &theFileSpec )) {
  72.         SetCursor(*(GetCursor(watchCursor)));
  73.         gQuitFlag = false ;
  74.         gMainWindow = NewCWindow(nil,&rBounds,title,false,noGrowDocProc,(WindowPtr)-1,true,0) ;
  75.         SetWTitle( gMainWindow, theFileSpec.name );
  76.         ShowWindow( gMainWindow ) ;
  77.         SetPort( gMainWindow ) ;
  78.         
  79.         myErr = NewGWorld(    &myGWorld,
  80.                             32,
  81.                             &gMainWindow->portRect,
  82.                             nil,
  83.                             nil,
  84.                             0L );
  85.                             
  86.         SetCursor(&qd.arrow) ;
  87.                             
  88.         if( myErr == noErr ) 
  89.         {
  90.             TQ3ViewerObject            myViewer ;
  91.             short                    refNum ;
  92.             
  93.             
  94.             myViewer = Q3ViewerNew ( (CGrafPtr)myGWorld, 
  95.                                         &gMainWindow->portRect, 
  96.                                         kQ3ViewerDefault ) ;
  97.                                         
  98.             if( myViewer != NULL )
  99.             {
  100.                 myErr = FSpOpenDF ( &theFileSpec, fsRdPerm, &refNum ) ;
  101.                 if( myErr == noErr )
  102.                 {
  103.                     PicHandle        myPict = NULL ;
  104.                     
  105.                     Q3ViewerUseFile( myViewer, refNum ) ;
  106.                     SetPort( (GrafPtr)myGWorld ) ;
  107.                     Q3ViewerDraw( myViewer ) ;
  108.                     myPict = Q3ViewerGetPict( myViewer ) ;
  109.                     
  110.                     SetPort( gMainWindow ) ;
  111.                     DrawPicture( myPict, &gMainWindow->portRect ) ;
  112.                     
  113.                     while( !Button() )
  114.                         ;
  115.                 }
  116.             }
  117.         }
  118.     }
  119. }
  120.  
  121.